﻿using AutoMapper;
using MediatR;
using SheepStorage.API.Application.Command.LambWeaningCommand;
using SheepStorage.API.Baseclass;
using SheepStorage.Domain.Entity;
using SheepStorage.Service.Interface;

namespace SheepStorage.API.Application.CommandHandlers.LambWeaningHandler
{
    public class LambWeaningFillHandler:IRequestHandler<LambWeaningFillCommand,Results<LambWeaning>>
    {
        private readonly ILambWeaningService _lambService;
        private readonly IMapper _mapper;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="lambService"></param>
        /// <param name="mapper"></param>
        public LambWeaningFillHandler(ILambWeaningService lambService, IMapper mapper)
        {
            _lambService = lambService;
            _mapper = mapper;
        }


        /// <summary>
        /// 羔羊断奶单个数据
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<Results<LambWeaning>> Handle(LambWeaningFillCommand request, CancellationToken cancellationToken)
        {
            var list = _mapper.Map<LambWeaning>(await _lambService.LambWeaningInfo(request.LambWeaningId));

            return Results<LambWeaning>.DataResult(list);
        }
    }
}
